# coding = UTF-8
# @Time : 2022/01/17 16:20
# @Author : PP_YY
# @File : check.py
# @Description : 从导入的名单中检查未进行打卡的名单
import copy
import tkinter

top = tkinter.Tk()


def open_check_file(file_path):
    f = open(file_path, "r", encoding='utf-8').read()
    check_list = f.split('\n')
    return check_list


def get_signed_list(signed_file_path):
    signed = open_check_file(signed_file_path)
    for index1 in range(len(signed)):
         signed[index1] = signed[index1][signed[index1].index('.') + 2:]
    return signed


def who_unsigned(check_list, signed_list):
    unsigned_list = []
    if len(check_list) == len(signed_list):
        return True, unsigned_list
    for i in check_list:
        if i not in signed_list:
            unsigned_list.append(i)
    list_temp = copy.deepcopy(unsigned_list)
    for i in unsigned_list:
        for j in signed_list:
            if i in j:
                list_temp.remove(i)
    unsigned_list = list_temp
    return False, unsigned_list


def show_unsigned_list(flag, unsigned_list):
    if flag:
        print("已完成打卡！")
        return
    print("未打卡名单：")
    for i in unsigned_list:
        print(i)
    return


def get_show_text(flag, unsigned_list):
    text = ""
    if flag:
        text += "已完成全部打卡！"
        return text
    text += "未打卡名单：                                        \n"
    j = 1
    for i in unsigned_list:
        if j % 5 == 0:
            text += i
            text += '\n'
        else:
            text += i
            text += '  '
        j += 1
    return text

def main():
    global top
    check_file_path = "花名单导入.txt"
    signed_file_path = "已打卡名单导入.txt"
    check_list = open_check_file(check_file_path)
    signed_list = get_signed_list(signed_file_path)
    flag, unsigned_list = who_unsigned(check_list, signed_list)
    show_unsigned_list(flag, unsigned_list)
    top.destroy()
    show = tkinter.Tk()
    show.title("打卡检测")
    show.geometry('500x300')
    show.resizable(0, 0)
    show_unsigned_label = tkinter.Label(show, text=get_show_text(flag, unsigned_list), anchor='w', justify='left', font=('等线', 19))
    show_unsigned_label.pack()



def test():
    # str1 = "佛山麦晓晴"
    # list1 = ['广州 黄家威', '潘剑鸿', '潘剑锋', '佛山麦晓晴']
    # list2 = ['黄家威', '潘剑鸿', '麦晓晴']
    # list = []
    # str2 = "麦晓晴"
    # for i in list2:
    #     if i not in list1:
    #         list.append(i)
    # print(list)
    # list_temp = copy.deepcopy(list)
    # for i in range(len(list)):
    #     for j in range(len(list1)):
    #         print(i, j)
    #         if list[i] in list1[j]:
    #             list_temp.remove(list[i])
    #             print(list[i], list1[j])
    #             print(i, j)
    # print(list)
    # print(list_temp)
    global top
    top.title("打卡检测")
    top.geometry('500x300')
    top.resizable(0, 0)
    notice = tkinter.Label(top, text="在花名单导入中写入信息\n并在导入已打卡名单的两个txt后，点击检测", width=40, font=('等线', 15))
    start_button = tkinter.Button(top, text="检测", command=main, bd=1, font=('等线', 30))
    notice.place(x=40, y=30)
    start_button.place(x=190, y=170)
    top.mainloop()

if __name__ == "__main__":
    # main()
    test()